<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

class BaseControlBase {
	var $feObj = NULL;
	var $modelObj = NULL;
	var $vObj = NULL;
	
	//contructor
	function BaseControlBase($action = '') {
		
	}
	
	//
	function init() {
		
	}
	
	function process() {
		$this->_doAction();
		$this->_doDisplay();
	}
	
	//methods
	function _doAction() {
		
	}
	
	function _doDisplay() {
		
	}
	
	//DISPLAY
	//
	function display_default() {
		
	}
	
	function display_item() {
		
	}
	
	function display_item_detail() {
		
	}
	
	function display_item_add() {
		$this->content_wrap['mainpart'] = 'addtype';
	}
	
	function display_item_edit() {
		$mainpart = $request_link_param['0'];
		$id = $request_link_param['1'];
		if( $id > 0 ) {
			$_valid = $adtObj->checkItem($id);
			if( $_valid == true ) {
				$items = $adtObj->getItems();
				$item = $adtObj->getItem($id);
				
				$content_wrap = array(
							'mainpart' => $mainpart,
							'items' => $items,
							'item' => $item,
									);
			} else {
				$content_wrap = array(
							'mainpart' => 'notype',
								);
			}
		} else {
			$is_default = true;
		}
	}
	
	function display_item_delete() {
		
	}
	
	function display_items() {
		
	}
	
	function display_items_detail() {
		
	}
	
	function display_items_search() {
		
	}
	
	//ACTION
	//
	function do_action_default() {
		
	}
	
	function do_action_add() {
		$this->vObj->checkNull($_POST, array('name'));
		if( $this->vObj->_valid() ) {
			$data_array = $this->modelObj->_post_field($_POST, 'type', 'field');
			$adtObj->addItem($data_array);
			//
			$this->feObj->redirect($request_link_current, 's');
		} else {
			$GLOBALS['_SUBMITTED_'] = 1;
			
			$vm = $this->vObj->_result("Error");
			$injectObj->addb('func_get_tpl_pagelayout_content', 'content_wrap', 'vm', $vm);
		}
	}
	
	function do_action_update() {
		$data_array = array();
		$id = trim(strtolower(util_get_param($_POST, 'id')));
		if( $id > 0 ) {
			$vObj->checkNull($_POST, array('name'));
			if( $vObj->_valid() ) {
				$data_array = array(
						'types_name' => $_POST['field_name'],
						'types_code' => $_POST['field_code'],
						'types_description' => $_POST['field_description'],
						'types_sort_order' => $_POST['field_sort_order'],
						'types_status' => $_POST['field_status'],
							);
				$adtObj->updateItem($id, $data_array);
				//
				$this->feObj->redirect($request_link_current, 's');
			} else {
				$GLOBALS['_SUBMITTED_'] = 1;
				
				$vm = $vObj->_result("Error");
				$injectObj->addb('func_get_tpl_pagelayout_content', 'content_wrap', 'vm', $vm);
			}
		} else {
			$this->feObj->redirect($request_link_current, 's');
		}
	}
	
	function do_action_delete() {
		$id = trim(strtolower(util_get_param($_POST, 'id')));
		if( $id > 0 ) {
			$adtObj->deleteItem($id);
		}
		//
		$this->feObj->redirect($request_link_current, 's');
	}
	
	function do_action_deletes() {
		
	}
	
	function do_action_setstatusopen() {
		
	}
	
	function do_action_setstatusclose() {
		
	}
}
//
?>